/**
 * 
 */
package com.java.test.datacenter.service.impl;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONObject;
import com.java.test.activity.dto.ActivityManageInfo;
import com.java.test.agent.module.info.AgentInfoService;
import com.java.test.agent.module.info.dto.AgentCensusDTO;
import com.java.test.agent.module.info.vo.AgentCensusVO;
import com.java.test.audit.dto.RemitPaymentInfo;
import com.java.test.audit.service.ExamineManageService;
import com.java.test.datacenter.dto.HaviorAllData;
import com.java.test.datacenter.dto.HaviorData;
import com.java.test.datacenter.dto.HomeAccountInfo;
import com.java.test.datacenter.dto.HomePageItem;
import com.java.test.datacenter.dto.PayInmentInfo;
import com.java.test.datacenter.dto.PaymentInfo;
import com.java.test.datacenter.dto.SumAccountInfo;
import com.java.test.datacenter.dto.SumAccountList;
import com.java.test.datacenter.mapper.PaymentInfoMapper;
import com.java.test.datacenter.service.DataManageService;
import com.java.test.dto.ResponseDTO;
import com.java.test.paymanage.dto.PayChannelInfo;
import com.java.test.paymanage.mapper.PayChannelMapper;
import com.java.test.user.dto.DepositInfo;
import com.java.test.user.dto.DrawingChannelInfo;
import com.java.test.user.dto.ReflectInfo;
import com.java.test.user.dto.RunWaterInfo;
import com.java.test.user.mapper.AcountResetMapper;
import com.java.test.user.mapper.BehaviorMapper;
import com.java.test.user.mapper.DepositMapper;
import com.java.test.user.mapper.DrawingChannelMapper;
import com.java.test.user.mapper.MemberInfoMapper;
import com.java.test.user.mapper.ReflectMapper;
import com.java.test.user.mapper.RunWaterMapper;
import com.java.test.util.AcountType;
import com.java.test.util.DateUtil;
import com.java.test.util.HttpRestUtil;
import com.java.test.util.JsonUtil;
import com.java.test.util.PageInfo;

/**
 * @author Administrator
 *
 */
@Service
public class DataManageServiceImpl implements DataManageService {

	@Autowired
	AcountResetMapper acountResetMapper;
	@Autowired
	DepositMapper depositMapper;
	@Autowired
	ReflectMapper reflectMapper;
	@Autowired
	RunWaterMapper runWaterMapper;

	@Autowired
	MemberInfoMapper memberInfoMapper;

	@Autowired
	BehaviorMapper behaviorMapper;

	@Autowired
	PaymentInfoMapper paymentInfoMapper;

	@Autowired
	RestTemplate restTemplate;

	@Value("${get.game.active.url}")
	private String activeUrl;

	@Value("${get.game.accountuser.url}")
	private String acountuserUrl;

	@Value("${get.homepage.list}")
	private String useraccount3Day;

	@Value("${get.behavior.list}")
	private String behaviorUrl;

	@Value("${get.betting.list}")
	private String bettingUrl;

	@Autowired
	ExamineManageService examineManageService;

	@Autowired
	private AgentInfoService agentInfoService;

	@Autowired
	DrawingChannelMapper drawingChannelMapper;

	@Autowired
	PayChannelMapper payChannelMapper;

	@Autowired
	HttpRestUtil httpRestUtil;

	@SuppressWarnings("unused")
	@Override
	public SumAccountList dealAcountData(LocalDateTime startTime, LocalDateTime endTime) {

		SumAccountList info = new SumAccountList();

		List<SumAccountInfo> sumlist = new ArrayList<SumAccountInfo>();
		
		
		// 优惠总额
		double yhamount = depositMapper.selectyhchData(startTime, endTime);
		info.setYhsumAccount(yhamount);
		

		// 活动存款
		SumAccountInfo ainfo = depositMapper.selectStatisticsData(startTime, endTime);
		ainfo.setAccountName(AcountType.HDCK.getContent());

		// 在线存款
		SumAccountInfo binfo = depositMapper.selectonlineStatisticsData(startTime, endTime);
		binfo.setAccountName(AcountType.ZXCK.getContent());

		// 手动存款
		SumAccountInfo cinfo = acountResetMapper.selecthandaddStatisticsData(startTime, endTime);
		cinfo.setAccountName(AcountType.SDCK.getContent());

		// 用户提款
		SumAccountInfo dinfo = reflectMapper.selectuserreflectData(startTime, endTime);
		dinfo.setAccountName(AcountType.YHTK.getContent());

		// 手动扣款
		SumAccountInfo einfo = acountResetMapper.selecthandreduceStatisticsData(startTime, endTime);
		einfo.setAccountName(AcountType.SDKK.getContent());
		
		sumlist.add(ainfo);
		sumlist.add(binfo);
		sumlist.add(cinfo);
		sumlist.add(dinfo);
		sumlist.add(einfo);

		this.getocuraccontUser(startTime, endTime, info, sumlist);




		// 账目汇总 ==============
		// 实际收入
		double sj = ainfo.getTotalAmount() + binfo.getTotalAmount() + cinfo.getTotalAmount() - dinfo.getTotalAmount()
				- einfo.getTotalAmount();
		info.setRealIncome(sj);

		// 存款总计
		double ckzj = ainfo.getTotalAmount() + binfo.getTotalAmount() + cinfo.getTotalAmount();
		info.setDepositTotal(ckzj);

		// 提款总计
		double tkzj = dinfo.getTotalAmount() + einfo.getTotalAmount();
		info.setDrawingTotal(tkzj);

		// 交易流水汇总 =========
	
		// 用户汇总

		// 新用戶注冊数
		int registCount = memberInfoMapper.selectuserRegistCount(startTime, endTime);
		info.setRegistUserTotal(registCount);

		// 总用户注册数
		int allregistCount = memberInfoMapper.selectuserallRegistCount();
		info.setSumregistUserTotal(allregistCount);

		int userActive = behaviorMapper.selectActiveUsercount(startTime, endTime);
		info.setActiveUserTotal(userActive);

		info.setList(sumlist);

		// 代理統計

		AgentCensusDTO parm = new AgentCensusDTO();

		parm.setStartTime(startTime == null ? null : startTime.format(DateTimeFormatter.ofPattern(DateUtil.f3)));
		parm.setEndTime(endTime == null ? null : endTime.format(DateTimeFormatter.ofPattern(DateUtil.f3)));
		ResponseDTO<AgentCensusVO> response = agentInfoService.getAgentCensus(parm);
		AgentCensusVO data = response.getData();
		info.setNewpeopAccount(Integer.valueOf(data.getNewAgentNum()));
		info.setSumagentAccount(Integer.valueOf(data.getAgentNum()));
		info.setSumrefectagentAmount(Double.valueOf(data.getAgentFunds()));

		return info;
	}

	@Override
	public PageInfo<PaymentInfo> selectpaymentInfoList(PageInfo<PaymentInfo> page) {
		PaymentInfo info = page.getInfo();

		int total = paymentInfoMapper.selectCount(info);

		List<PaymentInfo> list = paymentInfoMapper.selectpaymentList(page, info);

		if (list != null && list.size() > 0) {
			list = list.stream().sorted(Comparator.comparing(PaymentInfo::getAmount).reversed())
					.collect(Collectors.toList());
		}

		page.setTotalCount(total);

		page.setList(list);

		return page;
	}

	@Override
	public Double curToDaySumAmount(PaymentInfo info) {
		return paymentInfoMapper.selectpaymentcount(info);
	}

	@Override
	public List<RemitPaymentInfo> selectremitInfoById(PaymentInfo info) {
		return paymentInfoMapper.selectremitInfoById(info);
	}

	@Override
	public PageInfo<PayInmentInfo> selectpaymentInInfoList(PageInfo<PayInmentInfo> page) {
		PayInmentInfo info = page.getInfo();

		int total = depositMapper.selectComeAmoutCount(info.getStartTime(), info.getEndTime());

		List<PayInmentInfo> list = depositMapper.selectComeAmoutCountList(page, info.getStartTime(), info.getEndTime());

		if (list != null && list.size() > 0) {
			list = list.stream().sorted(Comparator.comparing(PayInmentInfo::getSumAmount).reversed())
					.collect(Collectors.toList());
		}

		list.forEach(b -> {
			int channelid = Integer.valueOf(b.getChannelName());
			PayChannelInfo temp = payChannelMapper.selectChannelInfobyid(channelid);
			if (temp != null) {
				b.setChannelName(temp.getChannelName());
			}
		});

		page.setTotalCount(total);

		page.setList(list);

		return page;
	}

	@Override
	public Double selectcurtoDayInamount(PayInmentInfo info) {
		return depositMapper.selectdepositcountupdate(info);
	}

	@Override
	public List<DepositInfo> selectdinfoBybankaccount(String bankAcount, LocalDateTime startTime,
			LocalDateTime endTime) {

		List<DepositInfo> list = depositMapper.selectdinfoBybankaccount(bankAcount, startTime, endTime);

		list.forEach(b -> {
			int channelid = b.getDepositChannel();
			PayChannelInfo temp = payChannelMapper.selectChannelInfobyid(channelid);
			if (temp != null) {
				b.setDepositChannelName(temp.getChannelName());
			}
		});

		return list;
	}

	@Override
	public JSONObject selectallRunwaterpage(PageInfo<RunWaterInfo> page) {
		RunWaterInfo info = page.getInfo();

//		int total = runWaterMapper.selectrunwaterCount(info.getGameAccount(), info.getStartTime(), info.getEndTime());
//
//		List<RunWaterInfo> list = runWaterMapper.selectrunWaterItemList(info.getGameAccount(), page,
//				info.getStartTime(), info.getEndTime());
//
//		page.setTotalCount(total);
//
//		page.setList(list);

		// 调用接口
		JSONObject obj = null;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("gameType", info.getGameType());
		params.put("gameName", info.getGameName());
		params.put("startTime", info.getStartTime());
		params.put("endTime", info.getEndTime());
		params.put("gameAccount", examineManageService.getGameUniqueNumber(info.getGameAccount()));
		params.put("pageNum", page.getCurrentPage());
		params.put("pageSize", page.getPageCount());
		params.put("orderId", info.getOrderId());

		String str = "";
		try {
			str = JsonUtil.obj2json(params);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.out.println(str);

		String response = null;

		try {
			response = httpRestUtil.postHttp(params, bettingUrl);
			obj = JSONObject.parseObject(response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return obj;

	}

	@Override
	public SumAccountList selectRunwaterCount(ActivityManageInfo infos) {
		// 投注
		SumAccountInfo ainfo = runWaterMapper.selectbetsData(infos.getStartTime(), infos.getEndTime());
		// 派彩
		SumAccountInfo binfo = runWaterMapper.selectPayoutData(infos.getStartTime(), infos.getEndTime());

		SumAccountList info = new SumAccountList();

		info.setBetToal(ainfo == null ? 0 : ainfo.getCount());
		info.setBetAoumtTotal(ainfo == null ? 0 : ainfo.getTotalAmount());
		info.setPrizeAcoumtTotal(binfo == null ? 0 : binfo.getTotalAmount());

		return info;
	}

	@Override
	public PageInfo<ReflectInfo> selecAmoutReflect(PageInfo<ReflectInfo> page) {
		ReflectInfo info = page.getInfo();

		int total = reflectMapper.selectreflectCount(info);

		List<ReflectInfo> list = reflectMapper.selectreflectList(page, info);

		list.forEach(b -> {
			int channelid = b.getReflectChannel();
			DrawingChannelInfo item = new DrawingChannelInfo();
			item.setId(channelid);
			DrawingChannelInfo tempinfo = drawingChannelMapper.selectdrawingchannelInfobyId(item);
			if (tempinfo != null) {
				b.setReflectChannelName(tempinfo.getChannelName());
			}

		});

		page.setTotalCount(total);

		page.setList(list);

		return page;
	}

	@Override
	public PageInfo<DepositInfo> selecAmoutDeposit(PageInfo<DepositInfo> page) {
		DepositInfo info = page.getInfo();

		int total = depositMapper.selectdepositCount(info);

		List<DepositInfo> list = depositMapper.selectdepositList(page, info);

		list.forEach(b -> {
			int channelid = b.getDepositChannel();
			PayChannelInfo temp = payChannelMapper.selectChannelInfobyid(channelid);
			if (temp != null) {
				b.setDepositChannelName(temp.getChannelName());
			}
		});

		page.setTotalCount(total);

		page.setList(list);

		return page;
	}

	@Override
	public JSONObject selectHaviorcount(String startTime, String endTime) {

		Map<String, Object> params = new HashMap<String, Object>();

		params.put("startTime", startTime);
		params.put("endTime", endTime);

		String resposedata = null;

		try {
			resposedata = httpRestUtil.postHttp(params, behaviorUrl);

			JSONObject obj = JSONObject.parseObject(resposedata);

			return obj;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<HaviorData> selectHavior(String startTime, String endTime, int type) {
		List<HaviorData> list = behaviorMapper.selectHavior(startTime, endTime, type);
		return list;
	}

	@Override
	public HaviorAllData selectHaviorexcel(String startTime, String endTime) {

		HaviorAllData info = new HaviorAllData();

		List<HaviorData> list1 = behaviorMapper.selectHavior(startTime, endTime, 1);

		List<HaviorData> list2 = behaviorMapper.selectHavior(startTime, endTime, 2);

		List<HaviorData> list3 = behaviorMapper.selectHavior(startTime, endTime, 3);

		List<HaviorData> list4 = behaviorMapper.selectHavior(startTime, endTime, 4);

		List<HaviorData> list5 = behaviorMapper.selectHavior(startTime, endTime, 5);

		List<HaviorData> list6 = behaviorMapper.selectHavior(startTime, endTime, 6);

		List<HaviorData> list7 = behaviorMapper.selectHavior(startTime, endTime, 7);

		List<HaviorData> list8 = behaviorMapper.selectHavior(startTime, endTime, 8);

		List<String> dateList = DateUtil.getTwoDaysDay(startTime, endTime);

		// 表示查询一天的每个小时
		if (dateList == null) {
			List<String> hour = Arrays.asList("00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
					"12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23");
			hour.forEach(b -> {
				info.setTime(b);
				list1.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount1(a1.getCount());
					}
				});
				list2.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount2(a1.getCount());
					}
				});
				list3.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount3(a1.getCount());
					}
				});
				list4.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount4(a1.getCount());
					}
				});
				list5.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount5(a1.getCount());
					}
				});
				list6.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount6(a1.getCount());
					}
				});
				list7.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount7(a1.getCount());
					}
				});
				list8.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount8(a1.getCount());
					}
				});

			});

			// 表示按照天查詢
		} else {
			dateList.forEach(b -> {
				info.setTime(b);
				list1.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount1(a1.getCount());
					}
				});
				list2.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount2(a1.getCount());
					}
				});
				list3.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount3(a1.getCount());
					}
				});
				list4.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount4(a1.getCount());
					}
				});
				list5.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount5(a1.getCount());
					}
				});
				list6.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount6(a1.getCount());
					}
				});
				list7.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount7(a1.getCount());
					}
				});
				list8.forEach(a1 -> {
					if (a1.getTime().equals(b)) {
						info.setCount8(a1.getCount());
					}
				});

			});
		}
		return info;
	}

	@Override
	public HomeAccountInfo selecthomeData(HomePageItem item) {

		HomeAccountInfo info = new HomeAccountInfo();

		// 昨日开始时间
		LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
		// 当天开始时间
		LocalDateTime endTime = LocalDateTime.of(LocalDate.now().plusDays(-1), LocalTime.MIN);

		// 昨日新增用户
		int yesaddUser = memberInfoMapper.selectuserRegistCount(startTime, endTime);
		info.setYesaddUser(yesaddUser);
		// 昨日活跃
		int yesactUser = behaviorMapper.selectActiveUsercount(startTime, endTime);
		info.setYesactUser(yesactUser);
		// 昨日存款
		SumAccountInfo sinfo = depositMapper.selectStatisticsData(startTime, endTime);
		double yesdespositUser = (sinfo == null ? 0l : sinfo.getTotalAmount());
		info.setYesdespositUser(yesdespositUser);

		// 昨日提款用户
		SumAccountInfo rinfo = reflectMapper.selectuserreflectData(startTime, endTime);
		double yesExaimUser = (rinfo == null ? 0l : sinfo.getTotalAmount());
		info.setYesExaimUser(yesExaimUser);
		// 平均在线时长
		double avgonlineTime = getavgTime();
		info.setAvgonlineTime(avgonlineTime);
		// 平台总用户
		int sumUser = memberInfoMapper.selectuserallRegistCount();
		info.setSumUser(sumUser);
		// 活动存款
		SumAccountInfo ainfo = depositMapper.selectStatisticsData(null, LocalDateTime.now());
		ainfo.setAccountName(AcountType.HDCK.getContent());

		// 在线存款
		SumAccountInfo binfo = depositMapper.selectonlineStatisticsData(null, LocalDateTime.now());
		binfo.setAccountName(AcountType.ZXCK.getContent());

		// 手动存款
		SumAccountInfo cinfo = acountResetMapper.selecthandaddStatisticsData(null, LocalDateTime.now());
		cinfo.setAccountName(AcountType.SDCK.getContent());

		// 用户提款
		SumAccountInfo dinfo = reflectMapper.selectuserreflectData(null, LocalDateTime.now());
		dinfo.setAccountName(AcountType.YHTK.getContent());

		// 手动扣款
		SumAccountInfo einfo = acountResetMapper.selecthandreduceStatisticsData(null, LocalDateTime.now());
		einfo.setAccountName(AcountType.SDKK.getContent());

		// 存款总金额
		double despSum = ainfo.getTotalAmount() + binfo.getTotalAmount() + cinfo.getTotalAmount();
		info.setDespSum(despSum);
		// 提款总金额
		double exaimSum = dinfo.getTotalAmount() + einfo.getTotalAmount();
		info.setExaimSum(exaimSum);

		// 三日用户信息================

		// 七日平台资金
		{
			// liuru
			List<HaviorData> lrlist = new ArrayList<HaviorData>();
			List<HaviorData> lclist = new ArrayList<HaviorData>();
			List<HaviorData> jylist = new ArrayList<HaviorData>();

			for (int i = 0; i < 7; i++) {

				LocalDateTime startTim = LocalDateTime.of(LocalDate.now().plusDays(-i), LocalTime.MIN);
				LocalDateTime endTim = LocalDateTime.of(LocalDate.now().plusDays(-i + 1), LocalTime.MIN);

				// 活动存款
				SumAccountInfo ainfo7 = depositMapper.selectStatisticsData(startTim, endTim);
				ainfo.setAccountName(AcountType.HDCK.getContent());

				// 在线存款
				SumAccountInfo binfo7 = depositMapper.selectonlineStatisticsData(startTim, endTim);
				binfo.setAccountName(AcountType.ZXCK.getContent());

				// 手动存款
				SumAccountInfo cinfo7 = acountResetMapper.selecthandaddStatisticsData(startTim, endTim);
				cinfo.setAccountName(AcountType.SDCK.getContent());

				// 用户提款
				SumAccountInfo dinfo7 = reflectMapper.selectuserreflectData(startTim, endTim);
				dinfo.setAccountName(AcountType.YHTK.getContent());

				// 手动扣款
				SumAccountInfo einfo7 = acountResetMapper.selecthandreduceStatisticsData(startTim, endTim);
				einfo.setAccountName(AcountType.SDKK.getContent());

				// 存款总金额
				double despSum7 = ainfo7.getTotalAmount() + binfo7.getTotalAmount() + cinfo7.getTotalAmount();

				// 提款总金额
				double exaimSum7 = dinfo7.getTotalAmount() + einfo7.getTotalAmount();

				double xlinfo = despSum7 - exaimSum7;

				HaviorData lrinfo = new HaviorData(String.valueOf(startTim.getDayOfMonth()), despSum7);
				HaviorData lcinfo = new HaviorData(String.valueOf(startTim.getDayOfMonth()), exaimSum7);
				HaviorData jyinfo = new HaviorData(String.valueOf(startTim.getDayOfMonth()), xlinfo);

				lrlist.add(lrinfo);
				lclist.add(lcinfo);
				jylist.add(jyinfo);

			}
			info.setLiuru(lrlist);
			info.setLiuchu(lclist);
			info.setJieyu(jylist);

			JSONObject info3 = get3dayuserStatistics(item.getTerminalName());
			info.setThreedaydata(info3);
		}

		return info;
	}

	/**
	 * 获取三日统计
	 * 
	 * @return
	 */
	public JSONObject get3dayuserStatistics(String TerminalName) {
		ResponseEntity<String> responseResultResponseEntity = null;
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("terminalName", TerminalName);

			HttpHeaders headers = new HttpHeaders();
			MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
			// 请勿轻易改变此提交方式，大部分的情况下，提交方式都是表单提交
			headers.setContentType(type);
			HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(params, headers); // 执行HTTP请求

			responseResultResponseEntity = restTemplate.postForEntity(useraccount3Day, objectHttpEntity, String.class);
			JSONObject obj = JSONObject.parseObject(responseResultResponseEntity.getBody());
			/*
			 * JSONObject todayNewUsers =obj.getJSONObject("todayNewUsers"); JSONObject
			 * todayNewUsers =obj.getJSONObject("todayNewUsers"); JSONObject todayNewUsers
			 * =obj.getJSONObject("todayNewUsers");
			 */
			return obj.getJSONObject("data");
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public double getavgTime() {
		ResponseEntity<String> responseResultResponseEntity = null;
		try {
			Map<String, Object> params = new HashMap<String, Object>();

			HttpHeaders headers = new HttpHeaders();
			MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
			// 请勿轻易改变此提交方式，大部分的情况下，提交方式都是表单提交
			headers.setContentType(type);
			HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(params, headers); // 执行HTTP请求

			responseResultResponseEntity = restTemplate.postForEntity(activeUrl, objectHttpEntity, String.class);
			JSONObject obj = JSONObject.parseObject(responseResultResponseEntity.getBody());

			return obj.getJSONObject("data").getDoubleValue("avgTime");
		} catch (Exception e) {
			e.printStackTrace();
			return 0l;
		}
	}

	public SumAccountList getocuraccontUser(LocalDateTime startTime, LocalDateTime endTime, SumAccountList info,
			List<SumAccountInfo> sumlist) {
		ResponseEntity<String> responseResultResponseEntity = null;
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("startTime", startTime);
			params.put("endTime", endTime);

			HttpHeaders headers = new HttpHeaders();
			MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
			// 请勿轻易改变此提交方式，大部分的情况下，提交方式都是表单提交
			headers.setContentType(type);
			HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(params, headers); // 执行HTTP请求
			responseResultResponseEntity = restTemplate.postForEntity(acountuserUrl, objectHttpEntity, String.class);
			JSONObject jsobj = JSONObject.parseObject(responseResultResponseEntity.getBody());

			JSONObject data = jsobj.getJSONObject("data");

			int curaccount = data.getIntValue("onLineMemberCount");
			int minsum = data.getIntValue("onLineMemberMin");
			int maxsum = data.getIntValue("onLineMemberMax");

			// 投注款
			SumAccountInfo finfo = new SumAccountInfo(AcountType.TZK.getContent(), data.getIntValue("inNumber"),
					data.getIntValue("inPeople"), data.getDouble("inAmount"));

			// 派奖款
			SumAccountInfo ginfo = new SumAccountInfo(AcountType.PJK.getContent(), data.getIntValue("outNumber"),
					data.getIntValue("outPeople"), data.getDouble("outAmount"));

			sumlist.add(finfo);
			sumlist.add(ginfo);

			// 用户统计
			info.setOnlineUserTotal(curaccount);
			info.setHighOnlineTotal(maxsum);
			info.setMinimumOnlineTotal(minsum);
			
			// 投注汇总
			info.setBetToal(finfo.getCount());
			info.setBetAoumtTotal(finfo.getTotalAmount());
			info.setPrizeAcoumtTotal(ginfo.getTotalAmount());

			return info;
		} catch (Exception e) {
			e.printStackTrace();
			return info;
		}

	}

}
